import Vue from 'vue'
import { getAction } from '@/api/manage'
import { FormTypes } from '@/utils/JEditableTableUtil'
import ReviewProgress from '../dialog/ReviewProgress.vue'
import { findBySelectSup, getAllList, findBySelectCus, findBySelectRetail, getUserList, getAccount,batchCounterAuditStatus } from '@/api/api'
import {getSubType} from '@/utils/detailType';
export const BillListMixin = {
  components: {
    ReviewProgress
  },
  data () {
    return {
      supList: [],
      addressList: [],
      cusList: [],
      retailList: [],
      userList: [],
      accountList: [],
      anotherDepotList:[],
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },

    isBatchDelEnabled: function () {
      for (let i = 0; i < this.selectedRowKeys.length; i++) {
        if (!this.selectionRows[i].actionsEnabled.delete) {
          return false
        }
      }
      return true
    }
  },
  
  created () {
  },
  methods: {
    getSubType,
    myHandleAdd () {
      this.$refs.modalForm.action = 'add'
      if (this.btnEnableList.indexOf(2) === -1) {
        this.$refs.modalForm.isCanCheck = false
      }
      this.handleAdd()
    },
    myHandleReleasePurchaseAdd () {
      this.$refs.releaseModalForm.action = 'add'
      if (this.btnEnableList.indexOf(2) === -1) {
        this.$refs.releaseModalForm.isCanCheck = false
      }
      this.handleReleasePurchaseAdd()
    },
    myHandleCopyAdd (record) {
      this.$refs.modalForm.action = 'copyAdd'
      if (this.btnEnableList.indexOf(2) === -1) {
        this.$refs.modalForm.isCanCheck = false
      }
      //复制单据的时候需要移除关联单据的相关信息
      record.linkNumber = ''
      record.billType = ''
      record.deposit = ''
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '复制新增'
      this.$refs.modalForm.disableSubmit = false
      //开启明细的编辑模式
      this.$refs.modalForm.rowCanEdit = true
    },
    myHandleEdit (record) {
      if (record.status === '0' || record.status === '4') {
        this.$refs.modalForm.action = 'edit'
        if (this.btnEnableList.indexOf(2) === -1) {
          this.$refs.modalForm.isCanCheck = false
        }
        this.handleEdit(record)
      } else {
        this.$message.warning(this.$t('popup.sorryEdited'))
      }
    },
    myHandleDelete (record) {
      if (record.status === '0') {
        this.handleDelete(record.id)
      } else {
        this.$message.warning(this.$t('popup.sorryOnlyDocumentsDeleted'))
      }
    },
    myHandleDetail (record, type) {
      this.handleDetail(record, type)
    },
    handleApprove (record) {
      this.$refs.modalForm.action = 'approve'
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '审核'
    },
    searchReset () {
      this.queryParam = {
        type: this.queryParam.type,
        subType: this.queryParam.subType,
        status: this.queryParam.status,
        roleType: Vue.ls.get('roleType')
      }
      this.loadData(1)
    },
    onDateChange: function (value, dateString) {
      this.queryParam.beginTime = dateString[0]
      this.queryParam.endTime = dateString[1]
    },
    // onDateCXTJChange(value, dateString) {
    //   this.form.setFieldsValue({
    //     startTime: dateString[0],
    //     endTime: dateString[1]
    //   })
    // },
    onDateOk (value) {
      console.log(value)
    },
    initSupplier () {
      let that = this
      findBySelectSup({}).then(res => {
        if (res) {
          that.supList = res
        }
      })
    },
    initAddressList () {
      let that = this
      getAllList({}).then(res => {
        console.log('List')
        if (res.data) {
          that.addressList = res.data
        }
      })
    },
    initCustomer () {
      let that = this
      findBySelectCus({}).then(res => {
        if (res) {
          that.cusList = res
        }
      })
    },
    initRetail () {
      let that = this
      findBySelectRetail({}).then(res => {
        if (res) {
          that.retailList = res
        }
      })
    },
    getDepotData () {
      getAction('/depot/findDepotByCurrentUser').then(res => {
        if (res.code === 200) {
          this.depotList = res.data
        } else {
          this.$message.info(res.data)
        }
      })
    },
    getAnotherDepotData () {
      getAction('/depot/findDepotList').then(res => {
        if (res.code === 200) {
          this.anotherDepotList = res.data
        } else {
          this.$message.info(res.data)
        }
      })
    },
    initUser () {
      getUserList({}).then(res => {
        if (res) {
          this.userList = res
        }
      })
    },
    initAccount () {
      getAccount({}).then(res => {
        if (res && res.code === 200) {
          let list = res.data.accountList
          this.accountList = list
        }
      })
    },
    openReviewProgress (record) {
      this.$refs.reviewProgress.show(record)
    }
  }
}
